﻿/* * 版 本 PIT-ADMS V7.0.3 敏捷开发框架
 * Copyright (c) 2013-2018 Hexagon PPM
 * 创建人：超级管理员
 * 日  期：2022-02-24 11:10
 * 描  述：对象类型
 */
var ProjectId = request('ProjectId');
var selectData = [];
var PropertyID = request('PropertyID');

var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            page.initGird();
            page.bind();
        },
        bind: function () {
            
            // 刷新
            $('#lr_refresh').on('click', function () {
                location.reload();
            });

            //获取当前选中的数据
            $.ajax({
                url: top.$.rootUrl + '/ZZDT_EC/ec_property/GetPropertyByObjectId',
                data: { propertyID: PropertyID, ProjectId: ProjectId },
                async: false,
                type: "GET",
                dataType: "json",
                success: function (data) {
                    if (data.code == 200 && data.data.length > 0) {
                        $.each(data.data, function (i, item) {
                            selectData.push(item.ObjectTypeID);
                        });
                    }
                },
                error: function () {
                },
                complete: function (data) {
                }
            });

            // 保存
            $('#lr_save').on('click', function () {
                var data = $('#dataTree').lrtreeSet("getCheckNodesEx");
                var objectTypeIDs = "";
                for (var i = 0; i < data.length; i++) {
                    objectTypeIDs += data[i].id + ",";
                }
                objectTypeIDs = objectTypeIDs.substring(0, objectTypeIDs.length - 1);
               
                var postData = {
                    objectTypeIDs: objectTypeIDs
                }
                $.lrSaveForm(top.$.rootUrl + '/ZZDT_EC/ec_property/SavePropertyO?propertyID=' + PropertyID + "&ProjectId=" + ProjectId, postData, function (res) {

                });
            });
        },
        initGird: function () {
            learun.loading(true, '正在获取数据');
            learun.httpAsyncGet(top.$.rootUrl + '/ZZDT_EC/ec_objecttype/GetTreeData?ProjectId=' + ProjectId + "&isShowCheck=true", function (res) {
                if (res.code == 200) {
                    var treeData = res.data;
                    $('#dataTree').lrtree({
                        data: treeData
                    });
                    setTreeData1();
                }
                setTimeout(function () {
                    learun.loading(false);
                });
            });
        },
        
    };
    page.init();
}

function setTreeData1() {
    if (!!selectData) {
        setTimeout(function () {
            $('#dataTree').lrtreeSet('setCheck', selectData);
        });
    }
    else {
        setTimeout(setTreeData1, 100);
    }
}